<?php  
//This is the basic view of the table and is the only table that contains the HREF to count.php.
//Saxon Dakin, 7392176
include 'menu.php';

// Open file and read to an array using new line as delimeter
$filename = "favourites.txt";
$fd = fopen ($filename, "r");
$favourites = fread ($fd,filesize ($filename));
fclose ($fd);
$splitfavourites = explode("\n", $favourites);

$counter =0;

//Turn into a seperate array named $items to split each line into 1 value per element
foreach ($splitfavourites as $value)
{
  $items[$counter] = explode("|", $value);
  $counter++;
}

//Turn into an HTML table
$favourites = "<table border='1'><tr><th>URL</th><th>Category</th><th>Date</th><th>Counter</th></tr>";
$sizeof_arr = sizeof($items);
$counter = 0;

//For loop to seperate each $items value into it's correct collum using the keys
for ($i=0; $i<$sizeof_arr; $i++)
{
  $favourites .= "<tr><td>";
  //href to count.php
  $favourites .=  "<a target='_blank' href='count.php?id=" . $items[$i][0] . "'>" . $items[$i][0] . "</a>";
  $favourites .=  "</td><td>" . $items[$i][1];
  $favourites .=  "</td><td>" . $items[$i][2];
  $favourites .=  "</td><td>" . $items[$i][3];
  $favourites .=  "</td></tr>";
}

$favourites .= "</tr></table>";

//Display table
echo $favourites;    

 ?> 